/**
 * ReportGear(2011)
 */
package net.abbp.report.context;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import net.abbp.report.view.GridView;
import com.reportgear.report.context.DefaultValues;

/**
 * 报表上下文背景
 * 
 * @version 1.0 2011-3-24
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since report 1.0
 */
public enum ReportContext {
    INSTANCE;

    /**
     * 实体主键Id，暂时用于保存的时候传递实体Id
     */
    private int entityId;
    private Locale locale = null;
    private DefaultValues defaultValues = null;

    // 当前表单
    private GridView gridView = null;
    // 历史表
    private GridView oldGridView = null;

    private int selectedObjectId;

    // 全局总线，用于数据传递
    private Map<String, Object> globalBus = new HashMap<String, Object>();

    private ReportContext() {
        setLocale(Locale.CHINA);
    }

    public Locale getLocale() {
        return locale;
    }

    public void setLocale(Locale locale) {
        if (locale == null) {
            return;
        }

        this.locale = locale;
    }

    public DefaultValues getDefaultValues() {
        if (defaultValues == null) {
            defaultValues = new DefaultValues();
        }
        return defaultValues;
    }

    public void setDefaultValues(DefaultValues paramDefaultValues) {
        defaultValues = paramDefaultValues;
    }

    /**
     * 获取当前视图
     * 
     * @return 当前视图
     */
    public GridView getCurrentView() {
        return gridView;
    }

    /**
     * 设置当前视图
     * 
     * @param gridView 当前视图
     */
    public void setCurrentView(GridView gridView) {
        this.gridView = gridView;
    }

    /**
     * 压入当前视图
     */
    public void pushCurrentView() {
        if (this.gridView != null) {
            this.oldGridView = this.gridView;
        }
    }

    /**
     * 弹出当前视图
     */
    public void popCurrentView() {
        if (this.oldGridView != null) {
            this.gridView = this.oldGridView;
            this.oldGridView = null;
        }
    }

    /**
     * 添加总线数据项
     * 
     * @param key 键
     * @param value 值
     */
    public void addBusItem(String key, Object value) {
        this.globalBus.put(key, value);
    }

    /**
     * 获取总线数据项
     * 
     * @param key 键
     * @return 值
     */
    public Object getBusItem(String key) {
        return globalBus.get(key);
    }

    /**
     * 设置实体主键Id
     * 
     * @param entityId 实体主键id
     */
    public void setEntityId(int entityId) {
        this.entityId = entityId;
    }

    /**
     * 获取实体主键Id
     * 
     * @return 实体主键Id
     */
    public int getEntityId() {
        return entityId;
    }

    /**
     * @return the selectedObjectId
     */
    public int getSelectedObjectId() {
        return selectedObjectId;
    }

    /**
     * @param selectedObjectId the selectedObjectId to set
     */
    public void setSelectedObjectId(int selectedObjectId) {
        this.selectedObjectId = selectedObjectId;
    }
}
